package com.boang.controller;

import com.boang.domain.Topic;
import com.boang.resp.Result;
import com.boang.service.OssService;
import com.boang.service.TopicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/*
  @author: 13813
  @date: 2024/9/10 14:10
*/
@RestController
@Tag(name = "话题")
public class TopicController {

    @Autowired
    private TopicService topicService;

    @Autowired
    private OssService ossService;

    @PostMapping("/addTopic")
    @Operation(summary = "新增话题",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    required = true,
                    content = {
                            @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = Topic.class)
                            )
                    }
            )
    )
    public Result<String> addTopic(@RequestBody Topic topic) {
        boolean saved = topicService.save(topic);
        return Result.ok();
    }

    @Operation(summary = "上传文件")
    @PostMapping("/upload")
    public Result<String> upload(@RequestPart MultipartFile file) throws Exception {
        return Result.ok(ossService.uploadFile(file));
    }

}
